<?php

namespace app\common\behavior;



use app\admin\model\LeescoreOrder;
use app\admin\model\LeescoreOrderGoods;
use app\common\model\custom\Info;
use app\common\model\shop\Goods;
use app\common\model\shop\Order;
use think\exception\ValidateException;

class Notice
{
    public function __construct() {

    }

    /* 积分商城通知*/
    public function leescore(&$data)
    {
        $config = [
            '1' =>  '您在积分商城购买的%s已发货，请前往积分订单查看',
            '2' => '您在积分商城购买的%s已被驳回，如有疑问请联系在线客服',
        ];
        $type = $data['type'];
        $id = $data['id'];
        try {
            $order = LeescoreOrder::get($id);
            $goods = LeescoreOrderGoods::where(['order_id'=> $order['id']])->select();
            foreach ($goods as $k => $v) {
                $insert = [
                    'user_id' => $order['uid'],
                    'name' => '发货通知',
                    'desc' => sprintf($config[$type], $v['goods_name'])
                ];


                Info::create($insert);
            }
        } catch (\Exception $e) {
            throw new ValidateException($e->getMessage());
        }


    }

    public function niu(&$data)
    {
        $config = [
            '1' =>  '您在牛商城预定的%s已被接受，请随时关注',
            '2' => '您在牛商城预定的%s已被驳回，如有疑问请联系在线客服',
            '3' => '您在牛商城预定的%s已被待定，如有疑问请联系在线客服',
            '4' => '您在牛商城预定的%s已被修改，如有疑问请联系在线客服',

        ];

        try {
            $type = $data['type'];
            $id = $data['id'];
            $order = Order::get($id);
            $goods = Goods::get($order['goods_id']);

            $info = sprintf($config[$type], $goods['name']);
            $insert = [
                'user_id' => $order['user_id'],
                'name' => '预定通知',
                'desc' => $info
            ];

            Info::create($insert);
        } catch (\Exception $e) {
            throw new ValidateException($e->getMessage());
        }

    }

}
